#include <unistd.h>
#include <windows.h>

//http://www.codeproject.com/KB/files/handles.aspx

int pipe(int * fd) {
	//Create two win32 handles and convert them to C-lib handles
	HANDLE hRead;
	HANDLE hWrite;
	BOOL retval = ::CreatePipe(&hRead, &hWrite, NULL, 4096);	//4kb buffer, Linux uses something like that
	if (retval == FALSE)	//error
		return -1;

	int osfRead  = _open_osfhandle((long)hRead, 0);
	int osfWrite = _open_osfhandle((long)hWrite, 0);
	fd[0] = osfRead;
	fd[1] = osfWrite;
	return 0;
}
